﻿using System;
using System.Collections.Generic;

using System.Text;
using System.Text.RegularExpressions;
using System.Web.UI;

namespace TA.Turbo.Controls
{
	/// <summary>
	/// Outputs Hidden controls in both view and edit modes.
	/// </summary>
	public class HiddenColumn : BaseDataColumn
	{
		/// <summary>
		/// Ctor.
		/// </summary>
		public HiddenColumn()
		{
			ViewCell.Visible = false;
			EditCell.Visible = false;
			Header.Visible = false;
			Footer.Visible = false;
		}
		/// <summary>
		/// Creates the view mode Hidden control.
		/// </summary>
		/// <param name="container"></param>
		public override void CreateViewItem(System.Web.UI.Control container, Grid owner)
		{
			if (string.IsNullOrEmpty(ViewControl.Id))
				ViewControl.Id = "hid" + Regex.Replace(this.Data.Field, "[^\\w]", "");
			Hidden h = new Hidden
			{
				ID = ViewControl.Id,
			};
			h.Data.Set(this.Data);
			container.Controls.Add(h);
		}
		/// <summary>
		/// Creates the edit mode Hidden control.
		/// </summary>
		/// <param name="container"></param>
		public override void CreateEditItem(System.Web.UI.Control container, Grid owner)
		{
			if (string.IsNullOrEmpty(EditControl.Id))
				EditControl.Id = "hid" + Regex.Replace(this.Data.Field, "[^\\w]", "");
			Hidden h = new Hidden
			{
				ID = EditControl.Id,
			};
			h.Data.Set(this.Data);
			container.Controls.Add(h);
		}

	}
}
